<template>
  <div v-show="showFlag" class="food" ref='food'>
      <div class="image-header">
          <img :src="food.image">
          <i class="back" @click="hide()"><</i>
      </div>
      <div class="content">
          <h1 class="title">{{food.name}}</h1>
          <div class="detail">
              <span class="sell-count">月售{{food.sellCount}}份</span>
              <span class="rating">好评率{{food.rating}}</span>
          </div>
          <div class="price">
              <span class="now">¥{{food.price}}</span><span class="old" v-show="food.oldPrice">¥{{food.oldPrice}}</span>
           </div>
      </div>
      <div class="cartcontrol-wrapper">
          <cartcontrol :food="food"></cartcontrol>
      </div>
      <div class="buy" v-show="!food.count || food.count == 0"></div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
import cartcontrol from '@/components/cartcontrol/cartcontrol'
export default {
    props:{
        food:{
            type:Object
        }
    },
    data(){
        return{
            showFlag:false,
        }
    },
    methods: {
        show(){
            this.showFlag = true;
            this.$nextTick(()=>{
                 if(this.scroll){
                    this.scroll.refresh();
                 }else{
                    this.scroll = new BScroll(this.$refs.food,{
                         click:true
                    })
                 }
            })
        },
        hide(){
            this.showFlag = false
        }
    },
    components: {
        cartcontrol
    }
}

</script>
<style>
.food{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 48px;
    z-index: 30;
    width: 100%;
    background: #fff;
}
.image-header{
    position: relative;
    width: 100%;
    height: 0;
    padding-top: 100%;
}
.image-header img{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.image-header .back{
    position: absolute;
    top: 10px;
    left: 0;
    padding: 10px;
    color: #fff;
    font-size: 28px;
}
.food .content{
    padding: 18px;
    text-align: left;
}
.food .content .title{
    line-height: 14px;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: rgba(7, 17, 27)
}
.food .content .detail{
    margin-bottom: 18px;
    line-height: 10px;
    font-size: 0;
    height: 10px;
}

.food .content .detail .sell-count , .food .content .detail .rating{
    font-size: 10px;
    color: rgba(147,153, 159)
}
.food .content .detail .sell-count{
    margin-right: 12px;
    font-size: 10px;
}
.food  .price{
    font-weight: 700;
    line-height: 24px;
}
.food .price .now{
    font-size: 14px;
    margin-top: 8px;
    color: rgb(240,20,20);
    margin-right: 10px;
}
.food  .price .old{
    text-decoration: line-through;
    font-size: 10px;
    color: rgb(147,153,159);
}
</style>
